package highestlevelentityhasonepk;

import org.eclipse.emf.ecore.EObject;

import org.eclipse.viatra2.emf.incquery.validation.runtime.Constraint;
import org.eclipse.viatra2.emf.incquery.validation.runtime.ValidationUtil;
import org.eclipse.viatra2.emf.incquery.runtime.api.impl.BaseGeneratedMatcherFactory;
import highestlevelentityhasonepk.HighestLevelEntityHasOnePKMatch;
import highestlevelentityhasonepk.HighestLevelEntityHasOnePKMatcherFactory;
import highestlevelentityhasonepk.HighestLevelEntityHasOnePKMatcher;

public class HighestLevelEntityHasOnePKConstraint extends Constraint<HighestLevelEntityHasOnePKMatch> {

	private HighestLevelEntityHasOnePKMatcherFactory matcherFactory;

	public HighestLevelEntityHasOnePKConstraint() {
		matcherFactory = new HighestLevelEntityHasOnePKMatcherFactory();
	}

	@Override
	public String getMessage() {
		return "Dude, $entity.name$ entity must have a primary key attribute!";
	}

	@Override
	public EObject getLocationObject(HighestLevelEntityHasOnePKMatch signature) {
		Object location = signature.get("entity");
		if(location instanceof EObject){
			return (EObject) location;
		}
		return null;
	}
	
	@Override
	public int getSeverity() {
		return ValidationUtil.getSeverity("error");
	}
	
	@Override
	public BaseGeneratedMatcherFactory<HighestLevelEntityHasOnePKMatch, HighestLevelEntityHasOnePKMatcher> getMatcherFactory() {
		return matcherFactory;
	}
}
